package transaction_demo.Util;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author haomin
 * @date 2022/04/08 20:11
 **/
public class DBUtil {
    private static final DataSource dataSource;
    static {
        MysqlDataSource db = new MysqlDataSource();
        String url = "jdbc:mysql://localhost:3306/0331_library?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai";
        db.setUrl(url);
        db.setUser("root");
        db.setPassword("123456");

        dataSource = db;
    }

    public static Connection connection() throws SQLException {
        return dataSource.getConnection();
    }
}